﻿using System;
using VIT.Web.UI;
using VIT.Web.Controls;
using VIT.Provider;
using System.Web.UI.WebControls;

namespace VIT.Web.Admin
{
    public partial class ModuleTrash : VITComponent
    {
        Module obj;

        protected void Page_Load(object sender, EventArgs e)
        {
            obj = new Module();

            load();
            pnAlert.Visible = false;
        }

        private void load()
        {
            load("ModifyDate");
        }
        private void load(string orderByField)
        {
            rpt.DataSource = obj.GetRecycleBin(orderByField, Convert.ToBoolean(Session["desc"]));
            rpt.DataBind();
        }

        public void ClearedList(string[] listId)
        {
            foreach (string id in listId)
                obj.Cleared(id);
        }

        private void setTrueVisible(System.Web.UI.HtmlControls.HtmlGenericControl control)
        {
            pnAlert.Visible = true;

            lblChon.Visible = false;

            control.Visible = true;
        }

        protected void btDelete_Click(object sender, EventArgs e)
        {
            string[] check = Request["itemCheckbox"].Split(',');
            if (check.Length > 0)
            {
                ClearedList(check);
                load();
                setTrueVisible(lblXoaVinhVien);
            }
            else setTrueVisible(lblChon);
        }

        protected void btBack_Click(object sender, EventArgs e)
        {
            string[] check = Request["itemCheckbox"].Split(',');
            if (check.Length >0)
            {
                obj.Delete(0, int.Parse(check[0]));
                load();
                setTrueVisible(lblPhucHoiThanhCong);
            }
            else setTrueVisible(lblChon); // thong bao chon it nhat 1 phan tu
        }

        protected void sortedChange_OnClick(object sender, EventArgs e)
        {
            LinkSubmit btn = (LinkSubmit)sender;
            Session["desc"] = !Convert.ToBoolean(Session["desc"]);
            load(btn.Param.ToString());
        }
    }
}
